//
//  KWTMGRNSettingCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/7/29.
//

#import "KWTMGRNSettingCell.h"
@interface KWTMGRNSettingCell()
@property (nonatomic, strong) QMUILabel *titleLab;

@property (nonatomic, strong) QMUITextField *leftTextField;

@property (nonatomic, strong) QMUITextField *rightTextField;
@end
@implementation KWTMGRNSettingCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}


-(void)setModel:(KWTMGRNSettingModel *)model
{
    _model = model;
    self.titleLab.text = model.rowTitle.rh_localized;
    
    KWTMGRNSettingModel *leftModel = [model.items firstObject];
    KWTMGRNSettingModel *rightModel = [model.items lastObject];
    self.leftTextField.text = leftModel.content;
    self.rightTextField.text = rightModel.content;
}

-(void)setupUI
{
    kWeakSelf;
    self.contentView.backgroundColor = kCOLOR_HEX(@"#F0F5FF");
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    
    QMUILabel *titleLab = [QMUILabel labelWithText:@"" font:kSYSTEMFONT(14) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    [bgView addSubview:titleLab];
    self.titleLab = titleLab;
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.left.mas_offset(15);
    }];
    
    _leftTextField = [[QMUITextField alloc]init];
    _leftTextField.textInsets = UIEdgeInsetsMake(0, 10, 0, 15);
    _leftTextField.userInteractionEnabled = NO;
    _leftTextField.layer.borderColor = kCOLOR_HEX_A(@"#7E868E", 0.3).CGColor;
    _leftTextField.layer.borderWidth = 1;
    _leftTextField.layer.cornerRadius = 5;
    _leftTextField.layer.masksToBounds = YES;
    _leftTextField.font = kSYSTEMFONT(14);
    _leftTextField.placeholder = @"请选择".rh_localized;
    [bgView addSubview:_leftTextField];
    [_leftTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab);
        make.height.offset(35);
        make.top.equalTo(titleLab.mas_bottom).offset(10);
        make.bottom.mas_offset(-5);
    }];
    
    UIImageView *arrow1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_down"]];
    [bgView addSubview:arrow1];
    [arrow1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(10);
        make.centerY.equalTo(weakSelf.leftTextField);
        make.right.equalTo(weakSelf.leftTextField).offset(-10);
    }];
    
    QMUILabel *lineLab = [QMUILabel labelWithFont:kSYSTEMFONT(15) textColor:kCOLOR_HEX_A(@"#7E868E", 0.3)];
    lineLab.text = @"-";
    lineLab.textAlignment = NSTextAlignmentCenter;
    [bgView addSubview:lineLab];
    [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.leftTextField.mas_right);
        make.centerY.equalTo(weakSelf.leftTextField);
        make.width.offset(60);
    }];
    
    _rightTextField = [[QMUITextField alloc]init];
    _rightTextField.textInsets = UIEdgeInsetsMake(0, 10, 0, 15);
    _rightTextField.userInteractionEnabled = NO;
    _rightTextField.layer.borderColor = kCOLOR_HEX_A(@"#7E868E", 0.3).CGColor;
    _rightTextField.layer.borderWidth = 1;
    _rightTextField.layer.cornerRadius = 5;
    _rightTextField.layer.masksToBounds = YES;
    _rightTextField.font = kSYSTEMFONT(14);
    _rightTextField.placeholder = @"请选择".rh_localized;
    [bgView addSubview:_rightTextField];
    [_rightTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lineLab.mas_right);
        make.height.width.equalTo(weakSelf.leftTextField);
        make.centerY.equalTo(weakSelf.leftTextField);
        make.right.mas_offset(-15);
    }];
    
    UIImageView *arrow2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_down"]];
    [bgView addSubview:arrow2];
    [arrow2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(10);
        make.centerY.equalTo(weakSelf.rightTextField);
        make.right.equalTo(weakSelf.rightTextField).offset(-10);
    }];
    
    QMUIButton *leftBtn = [[QMUIButton alloc]init];
    [bgView addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.leftTextField);
    }];
    
    QMUIButton *rightBtn = [[QMUIButton alloc]init];
    [bgView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.rightTextField);
    }];
    
    [[leftBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.selectAction1) {
            weakSelf.selectAction1(weakSelf.model);
        }
    }];
    
    [[rightBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.selectAction2) {
            weakSelf.selectAction2(weakSelf.model);
        }
    }];
}

@end
